#!/usr/bin/python3
# -*- coding: UTF-8 -*-
"""
字符串模式匹配
"""
import re
# 匹配以 f 开头的单词
print(re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest'))
# 去除连续重复的单词
print(re.sub(r'(\b[a-z]+) \1'r'', r'\1', 'cat in the the hat the the'))
# 字符替换，把 too 替换为 two
print('tea for too'.replace('too', 'two'))

1